﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web.Mvc;

namespace ProjectBase.Core
{
    /// <summary>
    ///     Business tier API for get operations
    /// </summary>
    /// <typeparam name = "TEntity"></typeparam>
    /// <typeparam name = "TID"></typeparam>
    /// <typeparam name = "TFilter"></typeparam>
    [ContractClass(typeof(Diagnostics.ReadFacade<,,>))]
    public interface IReadFacade<out TEntity, in TID, TFilter>
        : IReadFacade<TEntity, TID>
        , IFilterBinder<TFilter, TID>
        where TEntity : class, IPersistentObjectWithTypedId<TID>
        where TFilter : class, IFilter<TID>
    {
        /// <summary>
        ///     Basic read operation for filter-List.
        ///     Overriden implementations can use more specific filterObject
        /// </summary>
        /// <param name = "filter">basic filter parameters cluster, could be extended for Entity purposes and casted</param>
        /// <returns>Paged list of entities matching filter criteria</returns>
        IEnumerable<TEntity> Find(TFilter filter);

        /// <summary>
        ///     Factory method to get new instance of TFilter (therefore working also for interface or abstract TFilter...)
        ///     This method is expected to return the Filter parameters
        ///     which are fully instantiated, but containing no restrictions
        ///     (other words: Find(CreateNewFilter()) would return the unfiltered (but paged) list)
        /// </summary>
        /// <returns></returns>
        TFilter CreateNewFilter();

        /// <summary>
        ///     Returns the (JS) string representation of the UI evaluable validation rules.
        ///     (Example: validator.rules["LastName"] = { required: true, minlength: 1, maxlength: 50};)
        /// </summary>
        /// <param name="validationType">The switch which rule type to use. (e.g. "Add", "Update", "Find")</param>
        /// <returns>(JS) validation rules</returns>
        string ValidationRulesToString(string validationType);
    }
    [ContractClass(typeof(Diagnostics.ReadFacade<,>))]
    public interface IReadFacade<out TEntity, in TID> : IFacade
        where TEntity : class, IPersistentObjectWithTypedId<TID>
    {
        /// <summary>
        ///     Basic read operation for getting known entity
        /// </summary>
        /// <param name = "id">Entity unique int identifier</param>
        /// <returns>Entity instance or null</returns>
        TEntity GetById(TID id);

        /// <summary>
        ///     Returns new transient entity 'T'.
        ///     If overriden, some properties could be preset to business defaults.
        ///     (some Business rules therefore could be met).
        ///     Factory method instead of constructor is working also for interface or abstract 'T'...
        /// </summary>
        /// <returns>new entity 'T' transient</returns>
        TEntity CreateNew();
    }
}